package com.framework.service.config.dataTypeConfig.core;

import com.framework.common.annotation.DataType;
import com.framework.common.dataTypeConfig.core.ReplaceInterface;
import com.framework.common.model.dataType.DataTypeConstant;
import com.framework.common.util.other.NumeralUtil;
import com.framework.model.common.vo.TypeVo;
import com.framework.service.common.TypeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author 龘鵺
 * @className com.framework.service.config.dataTypeConfig.core.impl
 * @description 小数处理
 * @datetime 2025-01-09 11:11:11
 * @version 1.0
 */
@Service("dataDecimalServiceImpl")
@DataType(type = DataTypeConstant.DATA_TYPE_DECIMAL_TO_LEBEL)
public class DataDecimalServiceImpl implements ReplaceInterface<String> {

    @Autowired
    private TypeService typeServiceImpl;

    /**
     * @param value   1 判断值
     * @param type    2 数据类型键
     * @return String
     * @title 公共替换处理方法
     * @description 公共替换处理方法
     * @author 龘鵺
     * @datetime 2025-01-09 11:11:11
     */
    @Override
    public String getValue(Object value, String type) {
        String val = String.valueOf(value);
        if (StringUtils.isEmpty(val)) {
            return null;
        }

        List<TypeVo> typeVoList = typeServiceImpl.findByParentCodeList(type);
        //判断小数类型
        BigDecimal decimal = new BigDecimal(val);
        for (TypeVo item : typeVoList) {
            if (item.getTypeDecimal().compareTo(decimal) == NumeralUtil.POSITIVE_ZERO) {
                return item.getTypeName();
            }
        }
        return null;

    }
}
